﻿@model VietPremier.Areas.AdminCP.Models.Seo
@{
    ViewBag.Title = "Edit Seo Webiste";
    Layout = "~/Areas/AdminCP/Views/Shared/AdminLayout.cshtml";
}

<script type="text/javascript" src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-1.7.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-ui-1.8.16.custom.min.js")"></script>
<script type="text/javascript"  src="@Url.Content("~/ckeditor/ckeditor.js")"></script>
<script type="text/javascript" src="@Url.Content("~/ckfinder/ckfinder.js")"></script>

<script type="text/javascript">
    jQuery(document).ready(function () {
        $('#nofSuccess').hide(); // an thong bao
        $('#nofError').hide();

        readyValue();
    });
    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.search);
        if (results == null)
            return "";
        else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
    }
    function readyValue() {

        var id = getParameterByName("idSeo");
        var postURL = '@Url.Action("GetDetail", "AdminSEO")';
        //lay du lieu English
        $.post(postURL, { "idSeo": id }, function (data) {

            if (data.Id == "!") // khong lay duoc du lieu
            {
                alert("something wrong");
            }
            else {
                $("#Titletag").val(data.Titletag);
                $("#Meta_description").val(data.Meta_description);
                $("#Meta_keyword").val(data.Meta_keyword);
            }
        });

    }
    function CopyInformation() {
    
    }
    function alertMsg(msg) {
        $('#nofSuccess').hide();
        $('#nofError').show();
        $('#msgNofError').text(msg);
    }
    function getFileExtension(filename) {
        var ext = /^.+\.([^.]+)$/.exec(filename);
        return ext == null ? "" : ext[1];
    }
    function is_int(value) {
        for (i = 0; i < value.length; i++) {
            if ((value.charAt(i) < '0') || (value.charAt(i) > '9')) return false
        }
        return true;
    }
    function removeColorBox() {
        $("#Titletag").css("border", "1px solid #ccc");
        $("#Meta_description").css("border", "1px solid #ccc");
        $("#Meta_keyword").css("border", "1px solid #ccc");
        return false;
    }
    function checkField() {

        removeColorBox();

        //<!--SEO -->
        //check Title
        var Title = $("#Titletag").val();
        if (Title.length < 2 || Title.length > 200) {
            msg = "Title must have at most [2,200] characters.";
            decoded = $('<div/>').html(msg).text();
            alertMsg(decoded);
            alert(decoded);
            $("#Titletag").css("border", "1px solid red");
            $("#Titletag").focus();
            return false;
        }

        //check Meta_Description
        var MetaDescription = $("#Meta_description").val();
        if (MetaDescription.length < 2 || MetaDescription.length > 200) {
            msg = "Meta Description must have at most [2,200] characters.";
            decoded = $('<div/>').html(msg).text();
            alertMsg(decoded);
            alert(decoded);
            $("#Meta_description").css("border", "1px solid red");
            $("#Meta_description").focus();
            return false;
        }

        //check Meta_Keyword
        var MetaKeyword = $("#Meta_keyword").val();
        if (MetaKeyword.length < 2) {
            msg = "Meta Keyword must have at most 2 characters.";
            decoded = $('<div/>').html(msg).text();
            alertMsg(decoded);
            alert(decoded);
            $("#Meta_keyword").css("border", "1px solid red");
            $("#Meta_keyword").focus();
            return false;
        }

        //return false;
        return confirm("Are you sure you want to change?");
    }

</script>


<div class="maincontentinner">

    <ul class="maintabmenu">
        <li class="current"><a href="@Url.Action("Index", "AdminSEO")">Quản lý SEO</a></li>
    </ul>
    <!--maintabmenu-->

    <div class="notification msgsuccess" style="display: none" id="nofSuccess">
        <a class="close"></a>
        <p id="msgNofSuccess">This is a success message.</p>
    </div>
    <!-- notification msgsuccess -->

    <div class="notification msgerror" style="display: none" id="nofError">
        <a class="close"></a>
        <p id="msgNofError">This is an error message.</p>
    </div>
    <!-- notification msgerror -->

    <form id="formCreate" class="stdform stdform2" method="post" action="#" enctype="multipart/form-data">

        @if (Model != null)
        {
             <div class="contenttitle radiusbottom0">
                <h2 class="table"><span>MQuản lý SEO cho trang "@Model.Type"</span></h2>
            </div>
        }
        else
        {
            <div class="contenttitle radiusbottom0">
                <h2 class="table"><span>Quản lý SEO</span></h2>
            </div>
        }

        <p>
            <label>Title (*)</label>
            <span class="field">
                <input type="text" name="Titletag" id="Titletag" class="longinput" /></span>
        </p>

        <p>
            <label>Meta Description (*)</label>
            <span class="field">
                <input type="text" name="Meta_description" id="Meta_description" class="longinput" /></span>
        </p>

        <p>
            <label>Meta Keyword (*)</label>
            <span class="field">
                <textarea class="longinput" rows="5" cols="80" name="Meta_keyword" id="Meta_keyword"></textarea></span>
        </p>

        <p class="stdformbutton">
            <input type="submit" value="Accept" onclick="return checkField()" />
            <input type="submit" value="Back" onclick="javascript: history.back(); return false" />
        </p>

    </form>
    <br clear="all" />

</div>
<!--maincontentinner-->
